home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / ispell-3.1.18src / subset.x (.txt) < prev    next >
Microsoft Windows Help File Content  |  1995-01-23  |  7KB  |  153 lines

  1. : Use /bin/sh
  2. # $Id: subset.X,v 1.15 1995/01/08 23:23:47 geoff Exp $
  3. # Copyright 1992, 1993, Geoff Kuenning, Granada Hills, CA
  4. # All rights reserved.
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions
  7. # are met:
  8. # 1. Redistributions of source code must retain the above copyright
  9. #    notice, this list of conditions and the following disclaimer.
  10. # 2. Redistributions in binary form must reproduce the above copyright
  11. #    notice, this list of conditions and the following disclaimer in the
  12. #    documentation and/or other materials provided with the distribution.
  13. # 3. All modifications to the source code must be clearly marked as
  14. #    such.  Binary redistributions based on modified source code
  15. #    must be clearly marked as modified versions in the documentation
  16. #    and/or other materials provided with the distribution.
  17. # 4. All advertising materials mentioning features or use of this software
  18. #    must display the following acknowledgment:
  19. #      This product includes software developed by Geoff Kuenning and
  20. #      other unpaid contributors.
  21. # 5. The name of Geoff Kuenning may not be used to endorse or promote
  22. #    products derived from this software without specific prior
  23. #    written permission.
  24. # THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
  25. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. # ARE DISCLAIMED.  IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
  28. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34. # SUCH DAMAGE.
  35. #    Combine and resolve various dictionaries so they are proper
  36. #    subsets of one another, and so that maximal use is made of
  37. #    flags in the smaller ones.
  38. #    Usage:
  39. #    subset [-b base] [-l langfile] small-dict bigger-dict ... biggest-dict
  40. #    The output is a an equal number of successively-larger
  41. #    dictionaries.  The smallest is written to "dict.0".  Successive
  42. #    files are named "dict.1", "dict.2", and so forth, and each contains
  43. #    a list of words which should be added to the previous files to
  44. #    generate a dictionary.  Words which are in smaller dictionaries are
  45. #    effectively propagated to the larger ones, so that the smaller ones
  46. #    are proper subsets of their siblings.  If dictionaries are
  47. #    completely disjoint, this may result in an empty output dictionary.
  48. #    Affix flags are propagated to the smallest dictionary containing
  49. #    the root word;  this expands the effectiveness of small dictionaries
  50. #    at no cost in hash table space.
  51. #    The -b switch is used to specify a different base name for the
  52. #    output files than "dict".  (In other words, "-b english" would
  53. #    produce output in english.0, english.1, etc.).
  54. #    If the -l switch is specified, the language tables are gotten
  55. #    from the specified file;  otherwise they come from $LIBDIR/!!DEFLANG!!.
  56. #    Input dictionaries should be "clean";  if non-word characters
  57. #    appear in the dictionaries, the script may produce incorrect output.
  58. # $Log: subset.X,v $
  59. # Revision 1.15  1995/01/08  23:23:47  geoff
  60. # Support variable hashfile suffixes for DOS purposes.
  61. # Revision 1.14  1994/01/25  07:12:10  geoff
  62. # Get rid of all old RCS log lines in preparation for the 3.1 release.
  63. LIBDIR=!!LIBDIR!!
  64. TDIR=${TMPDIR-/usr/tmp}
  65. TMP=${TDIR}/sset$$.
  66. SORTTMP="-T ${TDIR}"            # !!SORTTMP!!
  67. USAGE="Usage:  subset [-b base] [-l langfile] dict-0 dict-1 ..."
  68. langtabs=${LIBDIR}/!!DEFLANG!!
  69. outbase=dict
  70. while :
  71.     case "$1" in
  72.         outbase="$2"
  73.         shift; shift
  74.         ;;
  75.         langtabs="$2"
  76.         shift; shift
  77.         ;;
  78.         echo "$USAGE" 1>&2
  79.         exit 1
  80.         ;;
  81.         break
  82.         ;;
  83.     esac
  84. if [ $# -lt 2 ]
  85.     echo "$USAGE" 1>&2
  86.     exit 1
  87. # Temp files
  88. MUNCHOUTPUT=${TMP}a
  89. MISSINGWORDS=${TMP}b
  90. TEMPDICT=${TMP}c
  91. FAKEDICT=${TMP}d
  92. FAKEHASH=${TMP}e!!HASHSUFFIX!!
  93. trap "/bin/rm -f ${TMP}*; exit 1" 1 2 15
  94. trap "/bin/rm -f ${TMP}*; exit 0" 13
  95. # Create a dummy dictionary to hold a compiled copy of the language
  96. # tables.
  97. echo 'QQQQQQQQ' > $FAKEDICT
  98. buildhash -s $FAKEDICT $langtabs $FAKEHASH \
  99.   ||  (echo "Couldn't create fake hash file" 1>&2; /bin/rm -f ${TMP}*; exit 1) \
  100.   ||  exit 1
  101. /bin/rm -f ${FAKEDICT}*
  102. # Figure out what the flag-marking character is.
  103. flagmarker=`ispell -D -d $FAKEHASH \
  104.   | sed -n '/^flagmarker/s/flagmarker //p'`
  105. case "$flagmarker" in
  106.     \\*)
  107.     flagmarker=`expr "$flagmarker" : '.\(.\)'`
  108. esac    
  109. #    (1) Use munchlist to create a list of roots and maximal suffixes.
  110. munchlist -l $langtabs "$@" | sort $SORTTMP > $MUNCHOUTPUT
  111. #    (2) Use join to add the maximal suffixes to each dictionary's roots.
  112. #        Re-expand this, combine with the original, and save for later.
  113. newline='
  114. dictno=0
  115. for dictfile
  116.     ispell -e -d $FAKEHASH < $dictfile | tr ' ' "$newline" \
  117.       | sort -u $SORTTMP | join "-t$flagmarker" -a1 - $MUNCHOUTPUT \
  118.       | ispell -e -d $FAKEHASH | tr ' ' "$newline" \
  119.       | sort -u $SORTTMP > ${TEMPDICT}.$dictno
  120.     dictno=`expr $dictno + 1`
  121. /bin/rm -f $MUNCHOUTPUT
  122. #    (3) For each adjacent pair of dictionaries, use comm to find words
  123. #        in the smaller that are missing from the larger, and add them
  124. #        to the larger.
  125. firstdict="$1"
  126. shift
  127. lastdict="${TEMPDICT}.0"
  128. dictno=1
  129. for dictfile
  130.     comm -23 $lastdict ${TEMPDICT}.$dictno > $MISSINGWORDS.$dictno
  131.     if [ -s $MISSINGWORDS.$dictno ]
  132.     then
  133.     sort $SORTTMP -o ${TEMPDICT}.$dictno \
  134.       ${TEMPDICT}.$dictno $MISSINGWORDS.$dictno
  135.     fi
  136.     lastdict="${TEMPDICT}.$dictno"
  137.     dictno=`expr $dictno + 1`
  138. /bin/rm -f $MISSINGWORDS.*
  139. #    (4) For each pair of dictionaries, use comm to eliminate words in
  140. #        the smaller from the larger, and shrink the result with munchlist.
  141. #        From this point out, we ignore interrupts.
  142. munchlist ${TEMPDICT}.0 > $outbase.0
  143. lastdict="${TEMPDICT}.0"
  144. dictno=1
  145. trap "" 1 2 13 15
  146. for dictfile
  147.     comm -13 $lastdict ${TEMPDICT}.$dictno \
  148.       | munchlist -l $langtabs > $outbase.$dictno
  149.     /bin/rm -f $lastdict
  150.     lastdict="${TEMPDICT}.$dictno"
  151.     dictno=`expr $dictno + 1`
  152. /bin/rm -f ${TMP}*
  153.